    package com.edu.bhu.admin.controller.admin;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.domain.LibRepertory;
import com.edu.bhu.admin.service.ILibRepertoryService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 库存Controller
 * 
 * @author wangweibo
 * @date 2022-02-16
 */
@Controller
@RequestMapping("/admin/repertory")
public class LibRepertoryController extends BaseController
{
    private String prefix = "admin/repertory";

    @Autowired
    private ILibRepertoryService libRepertoryService;

    @RequiresPermissions("admin:repertory:view")
    @GetMapping()
    public String repertory()
    {
        return prefix + "/repertory";
    }

    /**
     * 查询库存列表
     */
    @RequiresPermissions("admin:repertory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LibRepertory libRepertory)
    {
        startPage();
        List<LibRepertory> list = libRepertoryService.selectLibRepertoryList(libRepertory);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @RequiresPermissions("admin:repertory:export")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LibRepertory libRepertory)
    {
        List<LibRepertory> list = libRepertoryService.selectLibRepertoryList(libRepertory);
        ExcelUtil<LibRepertory> util = new ExcelUtil<LibRepertory>(LibRepertory.class);
        return util.exportExcel(list, "库存数据");
    }

    /**
     * 新增库存
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存
     */
    @RequiresPermissions("admin:repertory:add")
    @Log(title = "库存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LibRepertory libRepertory)
    {
        return toAjax(libRepertoryService.insertLibRepertory(libRepertory));
    }

    /**
     * 修改库存
     */
    @RequiresPermissions("admin:repertory:edit")
    @GetMapping("/edit/{repId}")
    public String edit(@PathVariable("repId") Long repId, ModelMap mmap)
    {
        LibRepertory libRepertory = libRepertoryService.selectLibRepertoryByRepId(repId);
        mmap.put("libRepertory", libRepertory);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存
     */
    @RequiresPermissions("admin:repertory:edit")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LibRepertory libRepertory)
    {
        return toAjax(libRepertoryService.updateLibRepertory(libRepertory));
    }

    /**
     * 删除库存
     */
    @RequiresPermissions("admin:repertory:remove")
    @Log(title = "库存", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(libRepertoryService.deleteLibRepertoryByRepIds(ids));
    }
}
